SHELL = /bin/sh
VPATH = @srcdir@

subdirs = @subdirs@
top_srcdir = @top_srcdir@
srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = $(exec_prefix)/bin
infodir = $(prefix)/info
libdir = $(prefix)/lib/gnudl
mandir = $(prefix)/man/man1

CC = @CC@
CPPFLAGS = @CPPFLAGS@
CFLAGS = $(CPPFLAGS) @CFLAGS@ 
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
INSTALL = @INSTALL@

USEPARALLEL := @USEPARALLEL@
USEINTERFACE := @USEINTERFACE@
USEGRAPHICS := @USEGRAPHICS@
USESHAREDHD := @USESHAREDHD@
OCAML := @OCAML@
OCAMLC := @OCAMLC@
OCAMLOPT := @OCAMLOPT@ @OCAMLFLAGS@
OCAMLDEP := @OCAMLDEP@
OCAMLTOP := @OCAMLTOP@

INCLUDE = `$(OCAMLC) -where`
export DEPEND = .depend

CCOPT := -cc $(CC) -ccopt "$(CFLAGS)" -ccopt "-I $(INCLUDE)"

DEPEND := .depend


OCAMLMPI = ../ocamlmpi/
OCAML_INCLUDES := -I $(OCAMLMPI) -I +camlp4 -I ./grappa -I ./graphps $(LABLTK)

all: $(DEPEND) $(FILES)

COBJS = uf.o \
	invdist.o correction.o binencode.o lists.o med_util.o \
	all_sorting_reversals.o vertex_factory.o hashtable.o \
	priority_stack.o sorting_reversal_median.o \
	inversion_median.o inversion_median_alberto.o grappa_interface.o 

libcamlgrappa.a: $(COBJS)
	rm -f $@
	ar rc $@ $(COBJS)

test_grappa: grappa.cmo	test_grappa.ml
	$(OCAMLC) $(CCOPT) $(OCAML_INCLUDES) -custom -cclib -g -cclib -L./ \
	-cclib -lcamlgrappa grappa.cma test_grappa.ml -o $@

.SUFFIXES: .ml .mli .cmo .cmx .cmi

$(DEPEND):	*.ml *.mli
	ocamldep -I $(INCLUDEOCAMLMPI) *.ml *.mli > $(DEPEND)

.ml.cmo:
	$(OCAMLC) -g -c $<

%.cmx: %.ml
	$(OCAMLOPT) -c $(CCOPT) $< $(PROFILE)

.ml.cmx:
	$(OCAMLC) -c $(CCOPT) $< $(PROFILE)

.mli.cmi:
	$(OCAMLC) -c -I $(INCLUDE) $(DEBUG) $<

.c.o:
	$(OCAMLOPT) $(CCOPT) -c $< $(PROFILE)


grappa.cmo: grappa.cmi

grappa.cmx: grappa.cmi

grappa.cma:  libcamlgrappa.a grappa.cmo 
	$(OCAMLC) -a -o grappa.cma -custom -cclib -L./ -cclib -lcamlgrappa grappa.cmo

grappa.cmxa:  libcamlgrappa.a grappa.cmx
	$(OCAMLOPT) -a -o grappa.cmxa -cclib -L./ -cclib -lcamlgrappa grappa.cmx
	
clean:	
	rm -f *.cmi *.cmo *.cmx *.o test_grappa *.cma *.cmxa *.a *.annot
